// -------------------------------------------------------------------------
// 		Copyright (C) 2018 - All Rights Reserved.
// -------------------------------------------------------------------------
//    	@FileName		:  	WFPluginLoader.cpp;
//    	@Author        	:  	webbleen@gmail.com;
//    	@Date         	:  	2018-07-13;
//    	@Desc			:	WFPluginLoader;
//
// -------------------------------------------------------------------------

#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <iostream>
#include <utility>
#include <thread>
#include <chrono>
#include <future>
#include <functional>
#include <atomic>
//#include "WFCPluginManager.h"
#include "WFComm/WFPluginModule/WFPlatform.h"




#if WF_PLATFORM == WF_PLATFORM_LINUX
#include <unistd.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <signal.h>
#include <sys/prctl.h>
#endif

std::string strArgvList;
std::string strDataPath;
std::string strPluginName;
std::string strAppName;
std::string strAppID;
std::string strTitleName;

void ProcessParameter(int argc, char* argv[])
{
	for (int i = 0; i < argc; i++)
	{
		strArgvList += " ";
		strArgvList + argv[i];
	}

	if (strArgvList.find("Path=") != std::string::npos)
	{
		for (int i = 0; i < argc; i++)
		{
			strDataPath = argv[i];
			if (strDataPath.find("Path=") != std::string::npos)
			{
				strDataPath.erase(0, 5);
				break;
			}
		}
		//WFCPluginManager::GetSingletonPtr()->SetConfigPath(strDataPath);
	}
	else
	{
		//WFCPluginManager::GetSingletonPtr()->SetConfigPath("../");
	}

	if (strArgvList.find(".xml") != std::string::npos)
	{
		for (int i = 0; i < argc; i++)
		{
			strPluginName = argv[i];
			if (strDataPath.find(".xml") != std::string::npos)
			{
				break;
			}
		}
		//WFCPluginManager::GetSingletonPtr()->SetConfigName(strPluginName);
	}

	if (strArgvList.find("Server=") != std::string::npos)
	{
		for (int i = 0; i < argc; i++)
		{
			strAppName = argv[i];
			if (strAppName.find("Server=") != std::string::npos)
			{
				strAppName.erase(0, 7);
				break;
			}
		}

		//WFCPluginManager::GetSingletonPtr()->SetAppName(strAppName);
	}

	if (strArgvList.find("ID=") != std::string::npos)
	{
		for (int i = 0; i < argc; i++)
		{
			strAppID = argv[i];
			if (strAppID.find("ID=") != std::string::npos)
			{
				strAppID.erase(0, 3);
				break;
			}
		}

		int nAppID = 0;
		if (WF_StrTo(strAppID, nAppID))
		{
			//WFCPluginManager::GetSingletonPtr()->SetAppID(nAppID);
		}
	}

	strTitleName = strAppName + strAppID;// +" PID" + NFGetPID();
	strTitleName.replace(strTitleName.find("Server"), 6, "");
	strTitleName = "WF" + strTitleName;

#if WF_PLATFORM == WF_PLATFORM_WIN
	SetConsoleTitle(strTitleName.c_str());
#elif WF_PLATFORM == WF_PLATFORM_LINUX
	prctl(PR_SET_NAME, strTitleName.c_str());
#endif


}
int main(int argc, char* argv[])
{
	
	return 0;
}

